package com.xk.springboot.exception;

import com.xk.springboot.dto.ResponseData;
import com.xk.springboot.dto.ResultData;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 * @author:Teacher黄
 * @date:Created at 2020/04/10
 */
@RestControllerAdvice
public class MyExceptionHandler {


    /**
     * 捕获 Exception及其子类的异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    ResultData  exceptionHandler(Exception e){
        return ResponseData.error(3001,"错误信息:"+e.getMessage());
    }


    /**
     * 捕获 文件上传相关的异常
     * @param e
     * @return
     */
    @ExceptionHandler(UploadException.class)
    ResultData uploadExceptionHandler(UploadException e){

       return ResponseData.error(e.getCode(), "文件上传异常:"+e.getMsg());
    }

}
